package com.lingrit.provider.utils;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class DataCheckUtils {
    /**
     * json 数据的校验
     * @param type
     * @param data
     * @return
     */
    public static boolean jsonDataCheck(String type, List<Map<String, Object>> data) {
        boolean isPass = true;
        String sql = "select * from lh_main_table where type=" + type;
        String tableName = null;
        try {
            tableName = EtlDbUtils.getTableName(sql);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
        String sql_col = "select * from " + tableName;
        List tableColumn = EtlDbUtils.queryTableColumn(EtlDbUtils.getConn(), sql_col);
        for (Map<String, Object> stringObjectMap : data) {
            Iterator iter = stringObjectMap.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                String key = (String) entry.getKey();
                boolean containsKey = tableColumn.contains(key);
                if(!containsKey){
                    return false;
                }
            }
        }
        return isPass;
    }
}
